﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net.Sockets;

namespace Wyse.Server.Base
{
    /// <summary>
    /// generic implementation of IClientContextFactory
    /// </summary>
    public class ClientContextFactory : IClientContextFactory
    {
        /// <summary>
        /// Ctor
        /// </summary>
        /// <param name="ctxType"></param>
        public ClientContextFactory(Type ctxType)
        {
            if (!ctxType.IsSubclassOf(typeof(ClientContext)))
                throw new ArgumentException();

            Type = ctxType;
        }

        public ClientContext CreateContext(TcpClient client)
        {
            return (ClientContext)Activator.CreateInstance(Type);
        }

        /// <summary>
        /// Gets the context type
        /// </summary>
        public Type Type
        {
            get;
            private set;
        }
    }
}
